import { getProxyJoin, subProxyJoin} from '../../../utils/networkRequest.js'
import {errorMsg} from '../../../utils/tool.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    i: "",
    t: "",
    dataInfo: null,
    showPop: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    let {
      i,
      t
    } = options;
    getProxyJoin(i, t, (r) => {
      if (r.code == 0) {
        this.setData({
          dataInfo: r.data,
          i: i,
          t: t,
        })
      } else {
        errorMsg(r.message);
      }
    })
  },
  //关闭弹窗
  popClose: function () {
    this.setData({
      showPop: false
    })
  },
  //申请加入团队
  joinProxy: function () {
    let {
      i,
      t,
      dataInfo,
      showPop
    } = this.data;
    let self = this;
    if (dataInfo.new) {
      self.setData({
        showPop: true
      })
    } else {
      subProxyJoin(i, t, (r) => {
        if (r.code == 0) {
          wx.redirectTo({
            url: '../../index/index',
          })
          setTimeout(function () {
            errorMsg(r.message)
          }, 400)
          
        } else {
          errorMsg(r.message);
        }
      })
    }
  },
  //未注册过的用户进来，前往注册
  goRegister: function () {
    let {
      i,
      t
    } = this.data;
    wx.navigateTo({
      url: '../newRegister/newRegister?i=' + i + "&t=" + t,
    })
  },
  //回首页
  goHome: function () {
    wx.reLaunch({
      url: '../../about/about',
    })
  }
})